home *** CD-ROM | disk | FTP | other *** search
/ Nebula 2 / Nebula Two.iso / Apps / ScreenSavers / BackSpaceViews / LazyView.BackModule / LazyView.m < prev    next >
Text File  |  1995-06-12  |  2KB  |  110 lines

  1. #import "LazyView.h"
  2. #import "LazyWraps.h"
  3.  
  4. #define SWAITTIME 1000        // wait 1 second
  5. #define WAITMAX 60        // max. time until next move in seconds
  6. #define R(max)    (random()&1023)/1024.0*(max)    // generate random number r, 0 <= r < max
  7. #define FONT "Helvetica-BoldOblique"
  8.  
  9. @implementation LazyView
  10.  
  11. + initialize
  12. {
  13.     srandom(time(0));
  14.     return self;
  15. }
  16.  
  17. - oneStep
  18. {
  19.     time_t t = time(0);
  20.  
  21.     if (![self timePassed: SWAITTIME])
  22.     return self;
  23.     
  24.     timestr = ctime(&t);
  25.  
  26.     PSWclearrect(x, y - 0.25 * size, size * 12.7, size * 1.05);        // delete old text
  27.    
  28.     if(--ticks <= 0) {        // if we have to move...
  29.     float tsx;        // text width
  30.     
  31.     ticks = (int)R(WAITMAX)+10;    // wait random time t until next move
  32.     size = floor(R(ms)) + 20;    // new random size within bounds
  33.     tsx = 12.5 * size;        // this is the approx. text width
  34.     x = R(mx-tsx);            // calc. position for text in screen
  35.     y = R(my-size) + size * 0.3;    // same for y and correct for chars like `g' (approx.)
  36.     r = R(0.8) + 0.2;        // calc. random color which is not too dark
  37.     g = R(0.8) + 0.2;
  38.     b = R(0.8) + 0.2;
  39.     [actFont = [Font newFont:FONT size:size matrix:NX_IDENTITYMATRIX] set];
  40.     PSWshowtext(timestr, x, y, r, g, b);
  41.     } else {
  42.     PSWshowtext(timestr, x, y, r, g, b);
  43.     }
  44.     return self;
  45. }
  46.  
  47. - initFrame:(NXRect *)frameRect
  48. {
  49.     ticks = 0;
  50.     x = y = 0;
  51.  
  52.     [super initFrame:frameRect];
  53.     [self setClipping:NO];        // not needed and faster...
  54.     actFont = [Font newFont:FONT size:30.0 matrix:NX_IDENTITYMATRIX];
  55.     [self newSize];
  56.     return self;
  57. }
  58.  
  59. - sizeTo:(NXCoord)width :(NXCoord)height
  60. {
  61.     [super sizeTo:width :height];
  62.     [self newSize];
  63.     return self;
  64. }
  65.  
  66. - drawSelf:(const NXRect *)rects :(int)rectCount
  67. {
  68.     if (!rects || !rectCount) return self;
  69.  
  70.     PSsetgray(0);
  71.     NXRectFill(rects);
  72.     ticks = 0;
  73.  
  74.     return self;
  75. }
  76.  
  77. - didLockFocus    // if we're lockFocused we have to reset the font
  78. {
  79.     [actFont set];
  80.     return self;
  81. }
  82.  
  83. - newSize        // this keeps the size legal
  84. {
  85.     mx = bounds.size.width;
  86.     my = bounds.size.height;
  87.     ms = mx/12.5 - 22;
  88.     ticks = 0;
  89.     return self;
  90. }
  91.  
  92. - (const char *)windowTitle
  93. {
  94.     return "Lazy";
  95. }
  96.  
  97. - inspector:sender
  98. {
  99.     char buf[MAXPATHLEN];
  100.     
  101.     if (!infoView) {
  102.     [NXBundle getPath:buf forResource:"Info" ofType:"nib" inDirectory:[sender moduleDirectory:"Lazy"] withVersion:0];
  103.     [NXApp loadNibFile:buf owner:self withNames:NO];
  104.     }
  105.  
  106.     return infoView;
  107. }
  108.  
  109. @end
  110.